home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / C / Blitter / BounceLine.c next >
Encoding:
C/C++ Source or Header  |  1997-12-23  |  2.1 KB  |  86 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o BounceLine.c -o BounceLine
  2. **
  3. ** Line bouncing demo that works on a screen of any type of dimensions as
  4. ** specified by the user in GMSPrefs.
  5. */
  6.  
  7. #include <proto/dpkernel.h>
  8.  
  9. BYTE *ProgName      = "Bounce Line";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "December 1997";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1997.  Freely distributable.";
  13. BYTE *ProgShort     = "Line bouncing demo.";
  14.  
  15. void main(void)
  16. {
  17.   struct GScreen *Screen;
  18.   struct JoyData *JoyData;
  19.   LONG palette[] = { PALETTE, 2, 0x000000L, 0x80f0f0L };
  20.   int  sx,sy,ex,ey;
  21.   int  dsx,dsy,dex,dey;
  22.  
  23.   if (Screen = InitTags(NULL,
  24.       TAGS_SCREEN,    NULL,
  25.       GSA_Palette,    palette,
  26.         GSA_BitmapTags, NULL,
  27.         BMA_AmtColours, 2,
  28.         TAGEND,         NULL,
  29.       GSA_Attrib,     DBLBUFFER,
  30.       TAGEND)) {
  31.  
  32.      sx = SlowRandom(Screen->Width);  dsx = -1;
  33.      sy = SlowRandom(Screen->Height); dsy = 2;
  34.      ex = SlowRandom(Screen->Width);  dex = 3;
  35.      ey = SlowRandom(Screen->Height); dey = 1;
  36.  
  37.      if (JoyData = Init(Get(ID_JOYDATA),NULL)) {
  38.  
  39.         Display(Screen);
  40.  
  41.         do
  42.         {
  43.           ClearBitmap(Screen->Bitmap);
  44.           Query(JoyData);
  45.           sx += dsx;
  46.           sy += dsy;
  47.           ex += dex;
  48.           ey += dey;
  49.  
  50.           if(sx<0) { sx = 0; dsx = -(dsx); }
  51.           if(sy<0) { sy = 0; dsy = -(dsy); }
  52.           if(ex<0) { ex = 0; dex = -(dex); }
  53.           if(ey<0) { ey = 0; dey = -(dey); }
  54.  
  55.           if(sx>Screen->Width-1) {
  56.             sx  = Screen->Width-1;
  57.             dsx = -(dsx);
  58.           }
  59.  
  60.           if(sy>Screen->Height-1) {
  61.             sy  = Screen->Height-1;
  62.             dsy = -(dsy);
  63.           }
  64.  
  65.           if(ex>Screen->Width-1) {
  66.             ex  = Screen->Width-1;
  67.             dex = -(dex);
  68.           }
  69.  
  70.           if(ey>Screen->Height-1) {
  71.             ey  = Screen->Height-1;
  72.             dey = -(dey);
  73.           }
  74.  
  75.           DrawUCLine(Screen->Bitmap,sx,sy,ex,ey,1);
  76.           WaitAVBL();
  77.           SwapBuffers(Screen);
  78.         } while (!(JoyData->Buttons & JD_LMB));
  79.  
  80.      Free(JoyData);
  81.      }
  82.   Free(Screen);
  83.   }
  84. }
  85.  
  86.